package com.ly.honor.controller;

import com.ly.honor.entity.User;
import com.ly.honor.entity.dto.UpdatePassDTO;
import com.ly.honor.service.UserService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author 李某人
 * @Date 2023/4/3 0:57
 * @Version 1.0
 */
@RestController
@RequestMapping("user")
@Validated
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("根据用户id修改密码")
    @PostMapping("updatePasswordById")
    public Result updatePasswordById(@RequestBody @Valid UpdatePassDTO updatePassDTO){
        userService.updatePasswordById(updatePassDTO);
        return Result.ok();
    }

    @ApiOperation("根据用户id查询用户")
    @GetMapping("getUserById/{id}")
    public Result getUserById(@PathVariable Integer id){
        User user = userService.getById(id);
        return Result.ok(user);
    }
}
